#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <pthread.h>
#include <sys/types.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <unistd.h>


void * read_mouse(void * arg)
{
    int fd;
    int cor;

    fd = open("./mouse",O_RDONLY);

    read(fd,&cor,sizeof(cor));

    printf("cor = %d\n",cor);

}

void * read_key(void * arg)
{
    char buffer[1024];

    while(1)
    {
        memset(buffer,0,sizeof(buffer));
        read(0,buffer,sizeof(buffer));
        printf("buffer = %s\n",buffer);
    }
}

int main()
{
    pthread_t id1;
    pthread_t id2;

    int ret = pthread_create(&id1,NULL,read_mouse,NULL);
    if(ret < 0)
    {
        perror("thread read mouse error!");
        exit(1);
    }

    ret = pthread_create(&id2,NULL,read_key,NULL);
    if(ret < 0)
    {
        perror("thread read key error!");
        exit(1);
    }

    pause();
    return 0;
}